<template>
  <div>
    <div class="liebiao">
      <div
        class="lis"
        table
        border="0"
        style="cursor: pointer"
        v-if="ismeir"
        @mouseover="jrtj"
        @mouseleave="jrtjtc"
      >
        <transition name="el-fade-in-linear">
          <div class="kow" v-show="dhuan.top">
            <span>根据您的口味生成每日更新</span>
          </div>
        </transition>
        <div class="igms">
          <div class="mogu">
            <img src="../../assets/reli/fem.png" alt="" />
          </div>

          <div class="mis">
            <img :src="dateimg[dates - 1]" alt="" />
          </div>
          <transition name="el-fade-in-linear">
            <div v-show="dhuan.bofan" class="transition-box">
              <div class="jinr">
                <img src="../../assets/bfs.png" alt="" />
              </div>
            </div>
          </transition>
        </div>
        <span class="text"> 每日歌曲推荐 </span>
      </div>
      <li
        class="lis"
        v-for="(item, index) in datm"
        :key="index"
        table
        border="0"
        style="cursor: pointer"
        @mouseover="jingr(index)"
        @mouseleave="chuq(index)"
        @click="toSongListDetails(item.id)"
      >
        <transition-group
          name="el-fade-in-linear"
          v-bind:css="false"
          v-on:before-enter="beforeEnter"
          v-on:enter="enter"
        >
          <div v-if="item.picUrl" v-bind:key="index">
            <div class="igms">
              <img :src="item.picUrl" alt="" />
              <div class="textshang">
                <span v-if="item.playcount">{{ item.playcount | jshu }}</span>
                <span v-else>{{ item.playCount | jshu }}</span>
                <div class="bof">
                  <img src="../../assets/tjlb/bf.png" alt="" />
                </div>
              </div>
              <transition name="el-fade-in-linear">
                <div v-show="ifdatass[index]" class="transition-box">
                  <div class="jinr">
                    <img src="../../assets/bfs.png" alt="" />
                  </div>
                </div>
              </transition>

              <div class="textxia"></div>
            </div>
            <span class="text">
              {{ item.name }}
            </span>
          </div>
        </transition-group>
      </li>
    </div>
  </div>
</template>

<script>
import API from "../../http/API";
export default {
  props: ["gedan"],
  watch: {
    gedan(val) {
      this.datm = val;
      this.show3 = !this.show3;
      // console.log("gets");
      // console.log(val);
      // console.log(this.datm);
    },
  },
  data() {
    return {
      datm: [],
      show3: false,
      ifdatass: [],
      //是否开启每日推荐
      ismeir: false,
      dateimg: [],

      //每日推荐动画显示
      dhuan: {
        bofan: false,
        top: false,
      },
      //定时器
      dings: null,
      //当前日期
      dates: null,
      //每日推荐歌曲
      meirData: [],
    };
  },
  created() {
    // this.datas = this.gedan;

    // console.log(this.$route.path);
    if (this.$route.path == "/home/recommendation") {
      this.ismeir = !false;
      this.meiruan();
      this.meirDate();
    } else {
      this.ismeir = false;
    }
  },
  mounted() {
    setTimeout(() => {
      this.show3 = !this.show3;
    });
  },
  methods: {




    
    // 动画钩子

    beforeEnter(el) {
      el.style.opacity = 0;
    },
    enter(el, done) {
      // console.log(el.dataset.index)
      let delay = el.dataset.index * 100;
      setTimeout(() => {
        el.style.transition = "opacity 0.4s ";
        el.style.opacity = 1;
        el.style.animation = "one-in 0.4s infinite";
        el.style["animation-iteration-count"] = 1;
        done();
      }, delay);
    },

    infen() {
      for (let index = 0; index < this.datm.length; index++) {
        this.ifdatass.push(false);
      }
    },
    jingr(index) {
      this.$nextTick(() => {
        this.ifdatass[index] = true;
        this.$forceUpdate();
      });
    },
    chuq(index) {
      this.$nextTick(() => {
        this.ifdatass[index] = false;
        this.$forceUpdate();
      });
    },
    //每日推荐
    meiruan() {
      this.$get(API.RECOMMEND_SONGS)
        .then((result) => {
          // console.log(result);
          this.meirData = result;
        })
        .catch((err) => {});
    },
    //每日推荐日期
    meirDate() {
      for (let index = 1; index <= 31; index++) {
        this.dateimg.push(require("../../assets/reli/" + index + ".png"));
      }
      // console.log(this.dateimg);
      var myDate = new Date();
      this.dates = myDate.getDate(); //获取当前日(1-31)
    },
    jrtj() {
      clearInterval(this.dings);
      this.dhuan.bofan = true;
      this.dings = setTimeout(() => {
        this.dhuan.top = true;
      }, 500);
    },
    jrtjtc() {
      clearInterval(this.dings);
      this.dhuan.bofan = false;
      this.dhuan.top = false;
    },
    toSongListDetails(e) {
      this.$router.push({
        path: "/Songlistdetails/songlist",
        query: {
          id: e,
        },
      });
    },
  },
  filters: {
    jshu: (value) => {
      // console.log(value);
      // console.log(value)
      if (value / 100000000 > 1) {
        return parseInt(value / 100000000) + "亿";
      } else {
        return parseInt(value / 10000) + "万";
      }
    },
  },
};
</script>

<style lang="less" scoped>
.kow {
  position: absolute;
  z-index: 5;
  top: 0;
  right: 0;
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgb(252, 252, 252);
  background-color: rgba(0, 0, 0, 0.452);
}
.mis {
  width: 50%;
  height: 50%;

  z-index: 10;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.mogu {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  // -webkit-filter: blur(2px);
  // -moz-filter: blur(2px);
  // -ms-filter: blur(2px);
  // -o-filter: blur(2px);
  // filter: blur(5px);
  position: relative;
  overflow: hidden;
  display: flex;
  align-content: center;
  justify-content: center;
  img {
    width: 100%;
    height: 100%;
  }
}
.mogu:after {
  content: "";

  width: 100%;

  height: 100%;

  position: absolute;

  left: 0;

  top: 0;

  background: inherit;

  // filter: blur(20px);
}
.text {
  /* 在恰当的断字点进行换行 */
  word-break: break-all;
  /* 超出范围隐藏 */
  overflow: hidden;
  /* 文字超出用省略号 */
  text-overflow: ellipsis;
  /* 盒子模型 */
  display: -webkit-box;
  /* 显示的文本行数 */
  -webkit-line-clamp: 2;
  /* 子元素的垂直排列方式 */
  -webkit-box-orient: vertical;
}
.liebiao {
  //   margin-top: 10px;
  @media only screen and (min-width: 800px) {
    // background-color:green;

    .das {
      //  max-width: 70%;

      margin: 0 auto;
      min-width: 650px;
      border: 1px solid #000;
    }
  }
  display: flex;
  justify-content: space-between;
  flex-flow: wrap;
  .lis {
    margin-bottom: 30px;
    flex-basis: 18%;
    // width:;
    height: 0;
    padding-bottom: 22%;
    border-radius: 5px;
    // border: 1px solid #000;
    &:nth-child(1) {
      position: relative;
    }
    .igms {
      position: relative;
      margin-bottom: 5px;
      // width: 100%;
      border-radius: 5px;
      overflow: hidden;
      display: flex;
      align-items: center;
      flex-direction: column;
      //   &::before {
      //     content: "❤️";
      //     color: red;
      //     background-color: rgba(0, 0, 0, 0.041);
      //   }
      img {
        width: 100%;
        height: 100%;
        border-radius: 5px;
      }
      .textshang {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 40px;
        z-index: 2;
        // border: 1px solid #000;
        display: flex;
        flex-direction: row-reverse;
        // align-items: center;
        background: linear-gradient(
          rgba(75, 74, 74, 0.425),
          rgba(255, 255, 255, 0.034)
        );

        span {
          margin-top: 5px;
          font-size: 0.9rem;
          color: rgb(255, 255, 255);
          margin-right: 5px;
        }
        .bof {
          margin-top: 8px;
          height: 10px;
          width: 10px;
          margin-right: 5px;
          display: flex;

          align-items: center;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
      .textxia {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 20px;
        z-index: 2;
        // border: 1px solid #000;
        background: linear-gradient(
          rgba(255, 255, 255, 0),
          rgba(14, 13, 13, 0.349)
        );
      }
      .jinr {
        position: absolute;
        z-index: 5;
        bottom: 10px;
        right: 10px;
        width: 30px;
        height: 30px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
    span {
      text-indent: 2px;
      line-height: 20px;
    }
  }
}
</style>